<%@page import="java.util.concurrent.CopyOnWriteArrayList"%>
<%@page import="org.mobicents.servlet.sip.example.CMessage"%>
<%@page import="org.mobicents.servlet.sip.example.CUser"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Manager dystrybucji wiadomości IM</title>
</head>
<body>

<h3>Manager dystrybucji wiadomości IM</h3>
<h4>w oparciu o kryteria lokalizacji i czasu</h4>

<br>

	
<form action="/call-blocking-1.7.0-SNAPSHOT/WebServlet" method="post">
<table>
<tr>
	<td>
		Grupy:
	</td>
	<td>
		Czas:
	</td>
	<td>
		Zarejestrowani użytkownicy:
	</td>
</tr>
<tr>
	 <td> 
	 <%
	 CopyOnWriteArrayList list2 = (CopyOnWriteArrayList) request.getAttribute("grupy");
	out.println("<SELECT name=groupSelected> <OPTION value='all' >Wszyscy</OPTION> ");
	for(int i=0; i<list2.size(); i++) {
	out.println("<OPTION value="+list2.get(i)+ ">"+list2.get(i)+"</OPTION> ");
	}
	out.println("</SELECT> ");
	
	 %>
 	</td>
 	<td> 
		 <Select name="godzina">
		 <OPTION value='-' selected> - </OPTION>
		 <% for(int i = 0; i <= 9 ; i++) out.println("<OPTION value=0"+i+ ">0"+ i +"</OPTION> ");  %>
		 <% for(int i = 10; i <= 23 ; i++) out.println("<OPTION value="+i+ ">"+ i +"</OPTION> ");  %>
		 </Select> 
		 : 
		 <Select name="minuta">
		  <OPTION value='00' selected> - </OPTION>
		 <% for(int i = 0; i <= 9 ; i++) out.println("<OPTION value=0"+i+ ">0"+ i +"</OPTION> ");  %>
		 <% for(int i = 10; i <= 59 ; i++) out.println("<OPTION value="+i+ ">"+ i +"</OPTION> ");  %>
		 </Select> 
 	</td>
	 <td rowspan="2" valign="top">
		<%
		CopyOnWriteArrayList<CUser> userList = (CopyOnWriteArrayList<CUser>) request.getAttribute("uzytkownicy");
		for(int i=0; i<userList.size(); i++) {
		out.println(userList.get(i).getIp() + "->" + userList.get(i).getLogin() + "<br>");
		}
		 %>
	 </td> 
 </tr>
 <tr>
   <td colspan="2"> 
	Wiadomość : 
	<br>
	<textarea name="message" id="message" cols="50" rows="10"></textarea>
	</td> 
 </tr>
 
<tr>
	<td> 
		<input type="submit" name="send" value="Wyślij">
	</td> 
	
</tr>
</table>

</form>

<br>
<SCRIPT LANGUAGE="JavaScript">
	document.write('<form><input type=button value="Odśwież" onClick="history.go()"></form>')
</script>

<h2>Zakolejkowane wiadomości:</h2>
<table border="1px">
	<tr>
		<th width="100px">
			Data
		</th>
		<th width="200px">
			Adresaci
		</th>
		<th width="400px">
			Treść
		</th>

		
	</tr>
	
					
		<%
		CopyOnWriteArrayList<CMessage> messageList = (CopyOnWriteArrayList<CMessage>) request.getAttribute("wiadomosci");
		if(messageList.size() == 0)
			out.println("<tr align=\"center\"> <br> <td colspan = \"3\"> Brak </td> </tr>");
		for( int i = 0; i < messageList.size(); i++ ) {
			CMessage cMessage = messageList.get(i);
			java.util.List<CUser> receivers = cMessage.getReceivers();
			
			 out.println("<tr valign=\"top\">");
			 	///Data
			 	out.println("<td>");
			 		out.println(cMessage.getTimeToDispatch());
			 	out.println("</td>");
			 	///Adresaci
			 	out.println("<td>");
			 		for( int j = 0; j < receivers.size(); j++ ) {
			 			out.println(receivers.get(j).getLogin() + "<br>");			 		
			 		}
		 		out.println("</td>");
		 		///Tresc
			 	out.println("<td>");
			 		out.println(cMessage.getMessage());
			 	out.println("</td>");

			 out.println("</tr>");
		}
		%>
			
</table>

</body>
</html>